<template>
	<div class="validate-body">
    <div class="search-block" v-if="showsearch">
      <searchtab @searchopen="opensearch" @checkstab="goindex" @linksearch="searchlink" :tablist="tablistprop"></searchtab>
    </div>
    <div class="search-block-new" v-if="showsearchlist">
      <searchlist @cansearch="searchcan" :searchprop="searchtext"></searchlist>
    </div>
    <div class="detail-top-tab pc-bk" >
      <navblock></navblock>
    </div>
		<div class="register-body" v-if="showtype === 1">
			<!-- <div class="register-validate" v-if="validate === 0">
				<div class="validate-text">
					请激活你的邮箱
				</div>
				<div class="back-home">
					<span @click="activateSuccess">点击激活</span>
				</div>
			</div> -->
			<div class="register-result">
				<div class="validate-text" v-if="success">
					您已成功激活，请登录官网
				</div>
				<div class="validate-text" v-else>
					该链接已失效！
				</div>
				<div class="back-home" @click="backHome">
					<span>确定</span>
				</div>
			</div>
		</div>
		<div class="new-passward" v-else>
			<div class="passward-title">
				设置新密码
			</div>
			<div class="passward-one">
				<span>输入密码：</span>
				<input type="password" v-model="newpassward1" placeholder="请输入密码" tabindex="2" onblur="">
			</div>
			<div class="passward-one">
				<span>确认密码：</span>
				<input type="password" v-model="newpassward2" placeholder="请输入密码" tabindex="2" onblur="">
			</div>
			<div class="back-home">
				<span @click="modifyPass">确认修改</span>
			</div>
		</div>
	</div>
</template>
<script type="text/javascript">
	import { Indicator, Lazyload, MessageBox } from 'mint-ui'
  import api from '../../utils/api'
  import apiConfig from '../../utils/apiconfig.js'
  import helper from '../../utils/helper'
  import crypt from '../../utils/crypto-helper-pkcs7'
  import navblock from '../mobile/components/nav'
  import searchtab from '../mobile/components/searchtab'
  import searchlist from '../mobile/components/search'
  import footernav from '../mobile/components/footernav'
  export default {
    data () {
      return {
      	newpassward1: '',
      	newpassward2: '',
      	success: false,
      	showtype: 0,
      	validate: 0,
        tablist: [],
        showsearchlist: false
      }
    },
    components: {
      navblock,
      searchtab,
      searchlist,
      footernav
    },
    created () {
      var tokenstr = this.$route.query.token
      // var tokenstr = '2IofChWmNoxeWerC61uh2p1a/jmZO3TWCZ2zmOpTm/JzccYiDg3Rgvih1wD1Pd2S'
      console.log(tokenstr)
      this.token = tokenstr
      tokenstr = tokenstr.replace(/\ +/g, '+')
      var avilatetoken = crypt.decrypt(tokenstr)
      var tokenjson = JSON.parse(avilatetoken)
      this.code = tokenjson.code
      console.log(tokenjson)
      if (tokenjson.type === 'REGISTER') {
      	this.activateSuccess(tokenjson.type)
      	this.showtype = 1
      } else {
      	this.showtype = 0
      }
    },
    methods: {
    	backHome () {
    		this.$router.push('/')
    	},
      activateSuccess (type) {
        var that = this
        var param = {
          token: that.token
        }
        console.log(param)
        api.GET(helper.getClientApiUrl(apiConfig.web.activateurl), param, res => {
          that.success = true
          that.validate = 1
          api.GET(helper.getClientApiUrl(apiConfig.web.activateurl), param, res => {
          }, res => {
          }, true)
        }, res => {
        	that.success = false
          that.validate = 1
          console.log(res)
          MessageBox('激活失败', res.msg)
        })
      },
      modifyPass () {
        var that = this
        var param = {
        	token: that.token,
          passwd: that.newpassward1,
          repass: that.newpassward2
        }
        console.log(param)
        api.GET(helper.getClientApiUrl(apiConfig.web.modfypassurl), param, res => {
          this.$router.push('/home')
        }, res => {
          MessageBox('修改失败', res.msg)
        })
      }
    }
  }
</script>
<style type="text/css">
	.back-home{
		display: inline-block;
	}
	.back-home span{
		display: inline-block;
		border:1px solid #A72037;
		height: 40px;
		line-height: 40px;
		padding: 0 20px;
		border-radius: 5px;
		color: #A72037;
		margin-top: 20px;
		font-size: 15px;
	}
	.validate-text{
		font-size: 18px;
		text-align: center;
	}
	.register-body{
		position: absolute;
		top: 40%;
		width: 100%;
		text-align: center;
	}
	.passward-title{
		font-size: 18px;
		margin-bottom: 10px;
		color: #A72037;
	}
	.passward-one span{
		font-size: 15px;
	}
	.passward-one input{
		height: 30px;
		line-height: 30px;
		border:1px solid #666;
		border-radius: 5px;
		outline: none;
		padding: 0 10px;
		width: 200px;
	}
	.passward-one{
		margin-bottom: 10px;
	}
</style>